<?php

use Illuminate\Database\Seeder;
use App\Models\V1\AdminUser;
use App\Models\V1\Role;
use App\Models\V1\Permission;

class RoleDataSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //
        //        创建用户角色
        $admin = new Role();
        $admin->name = 'admin';
        $admin->display_name = '管理员';
        $admin->description = '用户为管理员';
        $admin->save();

        $users = new Role();
        $users->name = 'users';
        $users->display_name = '普通用户';
        $users->description = '普通用户';
        $users->save();

        $all_permission = array_column(Permission::all()->toArray(),'id');
        $admin->perms()->sync($all_permission);

//        把角色分配给用户
        $user1 = AdminUser::find(1);
        $user1 -> attachRole($admin);
    }
}
